<!DOCTYPE html>
<html class="ui-page-login">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="__PUBLIC__/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/plugins/layer/layer.js"></script>
    <script src="__PUBLIC__/mui/js/mui.min.js"></script>
    <script src="__PUBLIC__/js/angular.js"></script>
    <script src="__PUBLIC__/common.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.css" />
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.picker.css" />
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.poppicker.css" />
    <script src="__PUBLIC__/mui/js/mui.picker.js"></script>
    <script src="__PUBLIC__/mui/js/mui.poppicker.js"></script>
    <style>

        #member-login{
            display: none;
        }
        .area {
            margin: 20px auto 0px auto;
        }

        .mui-input-group {
            margin-top: 10px;
        }

        .mui-input-group:first-child {
            margin-top: 20px;
        }

        .mui-input-group label {
            width: 35%;
            font-size: 15px;
            color: black;

        }

        .mui-input-row label~input,
        .mui-input-row label~select,
        .mui-input-row label~textarea {
            width: 65%;
            font-size: 15px;
            text-indent: 1em;
            color: #333333;
        }

        .mui-input::-webkit-input-placeholder
        {
            text-align: right;
            padding-right: 2em;
        }

        .mui-checkbox input[type=checkbox],
        .mui-radio input[type=radio] {
            top: 6px;
        }

        .mui-content-padded {
            margin-top: 25px;
        }

        .mui-btn {
            padding: 10px;
        }

        .link-area {
            display: block;
            margin-top: 25px;
            text-align: center;
        }

        .spliter {
            color: #bbb;
            padding: 0px 8px;
        }

        .oauth-area {
            position: absolute;
            bottom: 20px;
            left: 0px;
            text-align: center;
            width: 100%;
            padding: 0px;
            margin: 0px;
        }

        .oauth-area .oauth-btn {
            display: inline-block;
            width: 50px;
            height: 50px;
            background-size: 30px 30px;
            background-position: center center;
            background-repeat: no-repeat;
            margin: 0px 20px;
            /*-webkit-filter: grayscale(100%); */
            border: solid 1px #ddd;
            border-radius: 25px;
        }

        .oauth-area .oauth-btn:active {
            border: solid 1px #aaa;
        }

        .oauth-area .oauth-btn.disabled {
            background-color: #ddd;
        }

        .login-active {
            background: #f3363a;
        }
        .mui-input-group .enter{
            background: url("__PUBLIC__/images/enter-right.png")no-repeat;!important ;
            background-position: right 1em center;
            background-size: auto 50%;
        }
        a{
            text-decoration: none;

        }
    </style>
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css" />
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/local/zh-CN.js"></script>
</head>
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
<header class="mui-bar mui-bar-nav" style="background:#f3363a;" >
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white"></a>
    <h1 class="mui-title login-item" style="color: white">选择快递</h1>
</header>
<div class="mui-content" id="user-login" >
    <form class="mui-input-group" method="post" action="" style="margin-top: 0;  background: #efeff4;" data-validator-option="{stopOnError:false, timely:true,theme:'layer'}">
        <div class="mui-input-group">
            <div class="mui-input-row">
                <label>收货人</label>
                <input ng-model="order.name" type="text" readonly />
            </div>
            <div class="mui-input-row">
                <label>收货人电话</label>
                <input ng-model="order.phone" type="text" readonly />
            </div>
            <div class="mui-input-row">
                <label>收货人地址</label>
                <input ng-model="order.name_path" type="text" readonly />
            </div>
            <div class="mui-input-row">
                <label>收货人详细地址</label>
                <input ng-model="order.address" type="text" readonly />
            </div>
        </div>

        <div class="mui-input-group">
            <a href="javascript:void (0)">
                <div class="mui-input-row enter">
                    <label>快递公司</label>
                    <input name="code" ng-model="express" type="text" id="showUserPicker" class="mui-input-clear mui-input" placeholder="选择快递"  />
                     <input type="hidden" ng-model="expid" id="expid">
                </div> </a>
            <div class="mui-input-row">
                <label>运单号</label>
                <input name="logistics" id="logistics" ng-model="expsn" type="text" class="mui-input-clear mui-input" placeholder="填写运单" />
            </div>
        </div>
    </form>
    <div class="mui-content-padded">
        <button id="login" class="mui-btn mui-btn-block mui-btn-danger" style="line-height: 1" ng-click="submit()">确定</button>
    </div>
    <div class="mui-content-padded oauth-area">
    </div>
</div>

<include file="./Application/Home/View/pub/agentfoot.html" />
<script>
    var app = getApp('myApp', []);

    app.controller('Ctrl', function ($scope, $http) {
        $http({
            method: 'POST',
            data:{'id':getUrlParam('id'),'flg':getUrlParam('flg')},
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            transformRequest: function (obj) {
                var str = [];
                for (var p in obj) {
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                }
                return str.join("&");
            },
            url: "/index.php/Home/AgenOrder/onlineorderReceiveInfo"
        }).then(function successCallback(response) {
            //console.log(response.data);
            if (response.data.code == -1) {
                layer.msg(response.data.msg, {time: 1500});
            } else {
                $scope.logistics = response.data.data.logistics;
                $scope.order = response.data.data.order;
                var data=[];
                for (var x in $scope.logistics){
                    data[x]={};
                    data[x]['value']=$scope.logistics[x].code;
                    data[x]['text']=$scope.logistics[x].name;
                }
            }

            var userPicker = new mui.PopPicker();
            userPicker.setData(data);
            var showUserPickerButton = document.getElementById('showUserPicker');
            var userResult = document.getElementById('userResult');
            showUserPickerButton.addEventListener('tap', function(event) {
                userPicker.show(function(items) {
                    showUserPicker.value = items[0]['text'];
                    //expid.value = JSON.stringify(items[0]['value']);
                    $scope.code = items[0]['value'];
                });
            }, false);
        }, function errorCallback(response) {
            errorHandle(response);
        });


        $scope.submit = function () {
            var id = getUrlParam('id');
            var flg = getUrlParam('flg');
            if(flg == 'agen'){
                var data = {id:id,code: $scope.code, logistics: $("#logistics").val()};
                $http({
                    method: 'POST',
                    data: data,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/AgentOnlineorder/editagenorder"
                }).then(function successCallback(response) {
                    if (response.data.code == -1) {
                        layer.msg(response.data.msg, {time: 1500})
                    }
                    else if (response.data.code == 0) {
                        layer.msg("发货成功！", {time: 1500})
                        setTimeout(function () {
                            window.location.href="/index.php/Home/agen/orderlist"
                        }, 1500)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            } else {
                var data = {id:id,code: $scope.code, logistics: $("#logistics").val()};
                $http({
                    method: 'POST',
                    data: data,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/AgenOrder/deliver"
                }).then(function successCallback(response) {
                    if (response.data.code == -1) {
                        layer.msg(response.data.msg, {time: 1500})
                    }
                    else if (response.data.code == 0) {
                        layer.msg("发货成功！", {time: 1500})
                        setTimeout(function () {
                            window.location.href="/index.php/Home/agen/mylist"
                        }, 1500)
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            }
        }


    });
</script>
</body>
</html>